<template>
  <div id="app">
    <router-view class="content"></router-view>
    <div id="nav">
      <Footer
        v-if="
          $route.path == '/' ||
          $route.path.match('/home') ||
          $route.path == '/video' ||
          $route.path == '/minivideo' ||
          $route.path == '/me'
        "
      ></Footer>
    </div>
    <!-- 返回顶部 -->
    <div class="top" v-if="topType" @click="goTop">返回顶部</div>
  </div>
</template>

<script>
import Footer from "./components/Footer.vue";

export default {
  name: "App",
  data() {
    return {
      topType: false, //按钮是否显示
      scrollTop: "", //离顶部的距离
    };
  },
  components: {
    Footer,
  },
  created () {
    console.log(this.$route.path);
    //绑定 滚动事件
    window.addEventListener("scroll", this.handleScroll);
  },
  //卸载
  destroyed() {
    //解除绑定
    window.removeEventListener("scroll", this.handleScroll);
  },
  watch: {
    scrollTop() {
      if (this.scrollTop >= 300) {
        this.topType = true;
      } else {
        this.topType = false;
      }
    },
  },
  methods: {
    handleScroll() {
      console.log(this.$route.path);
      this.scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;
      if (this.scrollTop >= 300) {
        this.topType = true;
      }
    },
    goTop() {
      document.documentElement.scrollTop = 0;
      document.body.scrollTop = 0;
    },
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body,
html,
#app {
  height: 100%;
  width: 100%;
  scrollbar-width: none;
}

::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0 !important;
}

#app {
  font-family: PingFangSC-Regular, Hiragino Sans GB, sans-serif, Helvetica, 宋体;
  -webkit-touch-callout: inherit;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  display: flex;
  flex-direction: column;
}

#nav a {
  color: #2c3e50;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

#nav a.router-link-active {
  color: #f03d37;
}

a:hover {
  background: #fff;
}
a:active {
  background-color: transparent;
}
a:link {
  background-color: transparent;
}
a:visited {
  background-color: transparent;
}

.content {
  width: 100%;
  background-color: #fff;
  flex: 1;
  overflow: hidden;
}

.top {
  position: fixed;
  right: 0;
  bottom: 2.4rem;
  width: 2.2rem;
  height: 1rem;
  line-height: 1rem;
  z-index: 10;
  opacity: 0.94;
  background-image: linear-gradient(134deg, #fb3333, #ff5269 75%);
  box-shadow: 0 2px 4px 0 rgb(160 44 41 / 15%);
  border-radius: 20px 0 0 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 14px;
}
</style>
